import Mock from "mockjs";

const ApiPath = {
  list: "/todoList/page",
  number: "/todoList/number",
  detail: "/todoList/detail"
}

const todoList = Mock.mock(ApiPath.list, "post", (options=>{
  console.log("options",options.body)
  const { page=1, size=10, status=1 } = JSON.parse(options.body)
  const info = {
    code: 200,
    msg: '操作成功',
    ts: '@datetime()',
    data: {
      // 属性 list 的值是一个数组，其中含有 1 到 5 个元素
      'content|10': [{
          // 属性 sid 是一个自增数，起始值为 1，每次增 1
          'id|+1': 1,
          // 属性 userId 是一个5位的随机码
          'code|5': '',
          'name|5': '',
          'status': status,
          'createUser': '@CNAME',
          submitTime: '@datetime()',
      }],
      number: page,
      numberOfElements: 10,
      size: size,
      totalElements: 114,
      totalPages: 12,
    }
  }
  console.log(Mock.mock(info))
  return Mock.mock(info)
}))

const todoNumber = Mock.mock(RegExp(ApiPath.number + ".*"), "get", (options=>{
  const info = {
    code: 200,
    data: {
      needTodo: 10,
      hasTodo: 2,
      myTodo: 2,
    }
  }
  console.log(Mock.mock(info))
  return Mock.mock(info)
}))

const todoDetail = Mock.mock(RegExp(ApiPath.detail + ".*"), "get", (options=>{
  console.log(options)
  const info = {
    code: 200,
    msg: '操作成功',
    data: {
      
    }
  }
  console.log(Mock.mock(info))
  return Mock.mock(info)
}))